package com.fangzc.springboot.demo.common.exception;

import com.fangzc.springboot.demo.common.param.EnumRetCode;
import com.fangzc.springboot.demo.common.param.OutVoGlobal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Copyright (C) 2014-2016 天津紫藤科技有限公司. Co. Ltd. All Rights Reserved.
 *
 * @author fangzc
 * @version v1
 * @description 全局异常处理
 * @date 2019-5-28
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 全局捕获异常并向管理员发送邮件
     *
     * @param e
     * @throws Exception
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public OutVoGlobal handGlobalException(HttpServletRequest request, Exception e) {
        LOGGER.error("全局异常捕获，异常信息：--->", e);
        return OutVoGlobal.fail(EnumRetCode.SYSTEM_ERROR);
    }
}
